package com.woniuxy.createthread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO:
 * <P> Date: 2022/4/6:8:47
 * <P> Description:
 */
@Slf4j(topic = "c.FutureTaskCreat")
public class FutureTaskCreat {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> task = new FutureTask<>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                while (true) {
                    log.debug("running");
                    Thread.sleep(1000);
                }
            }
        });

        Thread thread = new Thread(task, "t1");
        thread.start();

        log.debug("{}", task.get());
        log.debug("end");

    }
}
